#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;

 };

class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        queue<TreeNode*>tree;
        vector<vector<int>>ans;
        if(root==NULL)return {};
        tree.push(root);
        int height=0;
        while(!tree.empty())
        {
            height=tree.size();
            ans.push_back(vector<int>());
            for(int i=1;i<=height;i++)
            {
                TreeNode*tmp=tree.front();
                tree.pop();
                ans.back().push_back(tmp->val);
                if(tmp->left)tree.push(tmp->left);
                if(tmp->right)tree.push(tmp->right);
            }            
        }
        return ans;
    }
};